/*
*作者---杨彬
*
*/
<template>
    <div>
    <section>
      <div class="address-warp2" v-if="!isHasAddress" @click="goSecletAddressFn()">
        <img src="../../assets/my/goArrow.png" class="go-arrow">
        <img src="../../assets/address/location.png"><span v-text="sData.sureOrder.notAddressText"></span>
      </div>
      <div class="address-warp" v-if="isHasAddress"  @click="goSecletAddressFn()">

        <img src="../../assets/my/goArrow.png" class="go-arrow com-div-middle-ab">
        <p class="name-tel-warp">
          <span class="name" v-text="addressData.consignee"></span>
          <span class="tel" v-text="addressData.phone"></span>
        </p>
        <div class="address-img-warp">
          <img class="com-div-middle-ab" src="../../assets/address/location.png">
          <p class="address" v-text="addressData.provinceName+addressData.cityName+addressData.districtName+addressData.detailAddress"></p>
        </div>
      </div>
      <div class="normal-emperature" v-if="isShowSend&&isGetEmsData">
        <span v-text="sData.sureOrder.sendWayText" class="text"></span>
        <label v-for="(sitem,sindex) in sendWay" class="sendWayLabel" v-if="(sitem.name!='自营配送'&&sitem.name!='闪送'&&sitem.shippingFreight)">
          <input type="radio" v-model="swObj" :value="sitem"
                 name="sw" :checked="sindex==1"><span v-text="sitem.name"></span>
        </label>

      </div>
      <div class="date-select-warp"  v-show="!isShowSend">
        <p class="title" v-text="sData.sureOrder.timeTitle"></p>
        <div class="date-select">
          <label for = "dates">
            <el-date-picker
             
              class= "date"
              v-model="value1"
              type="date" 
             @click='isToday'
              :placeholder="sData.sureOrder.dateItem[0]"
              :picker-options="picker"
              :editable = 'false'
              >
            </el-date-picker>
            <!-- <input type="text" name="send-date" id="send-date" readonly class="input date" placeholder="请填写配送日期" /> -->
            <img src="../../assets/sureOrder/date.png" class="com-div-middle-ab icon-date">
          </label>
          
          <label>
            <!-- <select @click="timeSlot" class="time-slot" id = "selectTime">
                <option v-for="(slot, index) in this.timeSlots" :selected="index===0?'selected':''">{{ slot }}</option>
            </select> -->
            <span  @click='showSlotBox'  class='time-slot' id='selectTime'>{{chooseTime}}</span>
            <ul class="timeBox" v-if = 'isShowTimeSlot'>
              <li v-for="(slot, index) in this.timeSlots" @click="changeTime(slot)">{{slot}}</li>
            </ul>
            
          </label>
          <img src="../../assets/sureOrder/dateTime.png" class="com-div-middle-ab icon-time" @click='showSlotBox'>
        </div>
      </div>
      <div class="content-warp">
        <div class="content-item-warp" v-for="uitem in productMsg">
          <img :src="uitem.img">
          <div class="content-item" :class="{imgAccountMore:defaultData.img.length>1}">
            <p class="title" v-text="uitem.name+(uitem.isCake=='1'?'(仅限成都配送)':'(全国配送)')"></p>
            <p class="detail" v-text="uitem.remark"></p>
          </div>
          <p class="money"
             v-text="sData.myOrder.detail.rmb+((Number(uitem.singlePrice)||Number(uitem.singlePrice)==0)?Number(uitem.singlePrice).toFixed(2):uitem.price)"></p>
          <p class="number"
             v-text="sData.myOrder.detail.textOther[0]+uitem.number"></p>
        </div>
      </div>
      <div class="coupon-remark-warp">
        <div>
          <span v-text="sData.sureOrder.function[0]"></span>
          <input type="text" name="remark" class="remark com-div-middle-ab" v-model="allWillSend.intro"
                 :placeholder="sData.sureOrder.function[1]" >
        </div>
        <div @click="goSelectCouponFN()">
          <span v-text="sData.sureOrder.function[2]"></span>
          <input type="text" name="sd" class="remark com-div-middle-ab" disabled 
                 :placeholder="$route.params.val?$route.params.val.name:(couponText?'请选择优惠券':'无优惠券可用')" >
          <img src="../../assets/my/goArrow.png" class="go-arrow">
        </div>
        <div>
          <span v-text="'可用'+myPoint+'积分抵￥'+myPoint/100"></span>
          <input class="mui-switch mui-switch-anim checkboxPoint com-div-middle-ab"
                 type="checkbox" :value="myPoint" v-model="isCanUsePoint" name='wewew'>
        </div>
      </div>
      <div class="cost-sum-warp">
        <div class="cost-sum-content">

          <p v-for="(gitem,gindex) in sData.myOrder.detail.textCost">
            <span class="cost-title" v-text="gitem.name"></span>
            <span class="cost-sum com-div-middle-ab"
                  v-text="allWillSend.totalQuality+sData.myOrder.detail.textOther[1]" v-if="gindex==0"></span>
            <span class="cost-number">
                   <span class="symbol" v-text="sData.myOrder.detail.costSymbol(gindex)"></span>
                   <span class="val" v-text="allWillSend.freight.toFixed(2)" v-if='gindex==2'></span>
                   <span class="val" v-text="allWillSend.shopingPoint?allWillSend.shopingPoint.toFixed(2):'0.00'" v-if='gindex==3'></span>
                   <span class="val" v-text="couponValue?couponValue.toFixed(2):'0.00'" v-if='gindex==4'></span>
                   <span class="val productRMB" v-text="(allWillSend.proMoney||allWillSend.proMoney==0)?allWillSend.proMoney.toFixed(2):(allWillSend.finalPrice.toFixed(2)?allWillSend.finalPrice.toFixed(2):'0.00')" v-if='gindex==0'></span>
                   <span class="val" v-text="allWillSend.toolPrice?allWillSend.toolPrice.toFixed(2):'0.00'" v-if='gindex==1'></span>
                </span>
          </p>
        </div>
      </div>
    </section>
      <div class="div-space"></div>
      <footer>

      <div class="footer-sum-warp">
        <span v-text="sData.sureOrder.footText[0]" class="pay-text"></span>
        <span class="price">
          <span v-text="sData.productCarSData.moneySymbol" class="symbol"></span>
          <span class="val" v-text="allWillSend.amountPaid"></span>
        </span>
      </div>
      <div class="footer-submit" v-text="sData.sureOrder.footText[1]" @click="goSubmit()"></div>
    </footer>
      <sure-order-alert :sData="sData" @upOperation='upOperation' v-if="openALert">

      </sure-order-alert>
      <!-- 弹框 -->
      <div class='pop' v-if="isChengduShow">
        <div>
          <p class='tit'>有仅限成都配送的商品</p>
          <p class='describ'>您选择了仅限成都配送商品,请点击[返回购物车]按钮删除该类商品,重新结算</p>
          <p class='btn'>
            <span class='cancel' @click="cancel">我知道了</span>
            <span class='submit' @click='goCart'>返回购物车</span>
          </p>
        </div>
      </div>
    </div>
</template>
<script type="text/javascript">
  import sureOrderAlert from 'src/components/com/sureOrderAlert/sureOrderAlert.vue';
  require('./../../../static/mobiscroll_date.css')
  export default {
    data(){
      return{
        couponName:m$.localStrages.get('currentCoupon')?m$.localStrages.get('currentCoupon').name:'',
        coupons:[],
        couponText:true,
        isChengduShow:false,
        isGetEmsData:false,
        openALert:false,
        addressData:'',
        swObj:'',
        couponMsg:"",//优惠卷信息
        introMsg:"",//备注信息
        productMsg:m$.localStrages.get('orderItemBeans'),//商品数组集合
        couponData:'',
        couponValue:0,
        sendWay:'',//配送方式
        myPoint:0,//可用积分
        value1: m$.localStrages.get('value1')?new Date((m$.localStrages.get('value1')+'').replace(/\-/g,'/')):'',
        picker: {
          disabledDate(time) {
            if(new Date().getHours()>16){
              return time.getTime() < Date.now() - 8.64e7 + 24*60*60*1000
            } else {
              return time.getTime() < Date.now() - 8.64e7
            }
          }
        },//配送日期
        
        timeSlots:["--请选择配送时间段--"],
        chooseTime:'',
        isShowTimeSlot:false,
        startHour: "14",
        startMinute: "00",
        endHour: "",
        endMinute: "",
        allWillSend:{

          member:"",//(required)用户idquery	string
          receiveId:m$.localStrages.get('addressId')?m$.localStrages.get('addressId'):'', //(required)收件地址idquery	string
          address:'1',//收件地址
          sendTime:'', //(required)配送时间query	string
          sendEndTime:'',
          shippingMethod:'',//配送方式query	string
          orderItemBeans:[],
          // orderItemBeans[0].thumbnail//商品项图片query	string
          // orderItemBeans[0].name//商品项名称query	string
          // orderItemBeans[0].sendType//配送类型query	string
          // orderItemBeans[0].intro//商品项备注query	string
          // orderItemBeans[0].quantity//商品项数量query	string
          // orderItemBeans[0].price//商品项价格query	string
          // orderItemBeans[0].productId//商品项商品idquery	string
          // orderItemBeans[0].cartId//购物车idquery	string
          intro:"",//订单备注query	string
          //couponCode:m$.localStrages.get('couponId')?m$.localStrages.get('couponId'):'',//优惠券idquery	string
          couponCode:this.$route.params.val?this.$route.params.val.couponCode:'',
          shopingPoint:0,//积分抵扣query	string
          totalQuality:1,//(required)订单商品数量总计query	string
          freight:0,//运费query	string
          totalAmount:0,//(required)订单总金额query	string
          amountPaid:''
        },
        isCanUsePoint:[],
        isHasAddress:false,
        isShowSend:false,
        defaultData:{ sendTime:"2017-1-11 10:00~11:00",
          orderTime:"2017-01-11 10:00",
          remark:"请尽快配送",
          number:10,
          status:"3",id:"232321111222",
          leftTime:'00:30:59',
          money:"100",title:'草莓千层水果蛋糕',
          detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',
          img:[1], freight:20,point:100,coupon:20,
          address:'',tel:'18202830089',name:'张虹'
        },
        couponId:m$.localStrages.get('couponId')?m$.localStrages.get('couponId'):'',
        addressId:m$.localStrages.get('addressId')?m$.localStrages.get('addressId'):'',
        postData:{
          "provinceCode": '',
          "cityCode":'',
          "districtCode": '',
          "productIds": '',
          "receiverAddress": '',
          "sendTime": ''
        },
        getCouponData:{
          "productIds": '',
          "productTotalPrices" : ''

        }
      }
    },
    components:{
      sureOrderAlert
    },
    updated(){
      this.accountMoney();
    },
    mounted (){
      //给日期插件加id 使点击图片有效果
      setTimeout(function(){
        m$.dom('.date input')[0].id = 'dates';
      },10)
    },
    methods:{
      isToday(val){
      },
      goCart () {
        m$.hiddenScroll(false);
        this.$router.replace('/productCar');
      },
      cancel () {
        this.isChengduShow = false;
        m$.hiddenScroll(false);
      },
      changeTime(time){
        this.isShowTimeSlot = false;
        this.chooseTime = time;
        m$.localStrages.set('chooseTime',this.chooseTime);
        console.log(m$.localStrages.get('chooseTime'));
        if(this.isShowSend == false){
          if(this.chooseTime.substr(6).length == 0){
            this.postData.sendTime = this.chooseTime+":00";
          }else{
            this.postData.sendTime = this.chooseTime.substr(6)+":00";
          }
        }
        this.getSendMethod();
      },
      showSlotBox (){
        this.isShowTimeSlot = !this.isShowTimeSlot;
      },
      timeSlot (bool) {
        this.timeSlots=[];
        
        if((new Date().getHours()) === 16 && (new Date().getMinutes())>29){
            this.timeSlots.push("22:00")
        } else if (new Date().getHours()>16 || new Date().getHours()<9) {
            for(var i = 0;i<16;i++){
                if (this.startMinute+30>59){
                    this.endHour = parseInt(this.startHour) + 1
                    this.endMinute = "00"
                } else {
                    this.endHour = this.startHour
                    this.endMinute = "30"
                }
                this.timeSlots.push(this.startHour + ":" + this.startMinute + "~" +this.endHour + ":" + this.endMinute)
                this.startHour = this.endHour
                this.startMinute = this.endMinute
            }
            this.timeSlots.push('22:00');
        } else {
            if (new Date().getMinutes()>29){
                    this.startHour = new Date().getHours() + 6
                    this.startMinute = "00"
                    var slot = (17-parseInt(new Date().getHours()))*2-2
                } else {
                    this.startHour = new Date().getHours() + 5
                    this.startMinute = "30"
                    var slot = (17-parseInt(new Date().getHours()))*2 - 1
                }
            for(var i = 0;i< slot;i++){
                if (this.startMinute === "00"){
                    this.startMinute = "00"
                    this.endHour = this.startHour
                    this.endMinute = "30"
                } else {
                    this.startMinute = "30"
                    this.endHour = parseInt(this.startHour) + 1
                    this.endMinute = "00"
                }
                this.timeSlots.push(this.startHour + ":" + this.startMinute + "~" +this.endHour + ":" + this.endMinute)
                this.startHour = this.endHour
                this.startMinute = this.endMinute
            }
            this.timeSlots.push('22:00');
        }
        if(bool==true){//是否取存的时间,选取地址优惠券的回显
          this.chooseTime = m$.localStrages.get('chooseTime')?m$.localStrages.get('chooseTime'):this.timeSlots[0];
          //上传后台,获取运费
          if(this.chooseTime.substr(6).length == 0){
            this.postData.sendTime = this.chooseTime+":00";
          }else{
            this.postData.sendTime = this.chooseTime.substr(6)+":00";
          }
        }else{
          this.chooseTime = this.timeSlots[0];
          m$.localStrages.set('chooseTime',this.chooseTime);
          //上传后台,获取运费
          if(this.chooseTime.substr(6).length == 0){
            this.postData.sendTime = this.chooseTime+":00";
          }else{
            this.postData.sendTime = this.chooseTime.substr(6)+":00";
          }
        }
      },
      accountMoney(){
        
        if(this.allWillSend.proMoney||this.allWillSend.proMoney==0){
          console.log('有ProMoney')
          console.log(this.allWillSend.proMoney)
          this.allWillSend.amountPaid=this.allWillSend.proMoney+this.allWillSend.freight+this.allWillSend.toolPrice-this.allWillSend.shopingPoint-this.couponValue;
        }else{
          
          console.log(this.allWillSend.toolPrice)
          console.log(this.allWillSend.finalPrice)
          this.allWillSend.amountPaid=this.allWillSend.finalPrice+this.allWillSend.freight+this.allWillSend.toolPrice-this.allWillSend.shopingPoint-this.couponValue;
        }
        console.log('算一下总价')
        this.allWillSend.amountPaid = this.allWillSend.amountPaid.toFixed(2);
        console.log(this.allWillSend.amountPaid)
      },
      goSubmit(){
        let isShowSend=false;
        var nowProductArr=this.productMsg;
        var nowCake=nowProductArr[0].isCake
        for(var i=0;i<nowProductArr.length;i++){
          if(nowProductArr[i].isCake == 1){
            isShowSend=true;
          }
        }
          
        var sObj={}
        for(var okey in this.allWillSend){
          if(okey!='orderItemBeans'){
            sObj[okey]=this.allWillSend[okey]
          }
        }
        //送货地址
        this.allWillSend.address = this.addressData.provinceName+this.addressData.cityName+this.addressData.districtName+this.addressData.detailAddress+""
        sObj.address=this.allWillSend.address
        console.log(this.isShowSend);
        if(this.isShowSend==false){
           //送达时间
          var oSelect = document.getElementById("selectTime");
          var idx = oSelect.selectedIndex;
          var sendDate = this.value1;
          console.log('配送时间啦')
          console.log(sendDate);
          console.log(typeof sendDate);
          console.log(JSON.stringify(sendDate).length);
          if(JSON.stringify(sendDate).length>12){
            if((typeof sendDate) == 'string'){
              this.allWillSend.sendTime = sendDate.getFullYear() + "-" + (sendDate.getMonth()+1) + "-" + sendDate.getDate() + " " + this.chooseTime;
            }else{
              this.allWillSend.sendTime = sendDate.getFullYear() + "-" + (sendDate.getMonth()+1) + "-" + sendDate.getDate() + " " + this.chooseTime;
            }
            
           }else{
            this.allWillSend.sendTime = sendDate + " " + this.chooseTime;
           }
         
          console.log(this.allWillSend);
          sObj.sendTime = this.allWillSend.sendTime

          if(this.chooseTime.substr(6).length == 0){
            this.allWillSend.sendEndTime = this.chooseTime;
          }else{
            this.allWillSend.sendEndTime = this.chooseTime.substr(6)
          }
          sObj.sendEndTime = this.allWillSend.sendEndTime
        }

        var sIB=this.allWillSend.orderItemBeans
        for(var i=0;i<sIB.length;i++){
          for (var skey in sIB[i]){
            sObj['orderItemBeans['+i+'].'+skey]=sIB[i][skey];
          }
        }
        //receiveId
        this.allWillSend.receiveId = this.addressData.id;
        sObj.receiveId = this.allWillSend.receiveId;

        //配送方式
        this.allWillSend.shippingMethod = this.swObj.shippingMethod;
        sObj.shippingMethod = this.allWillSend.shippingMethod;


        console.log(isShowSend);
        if(isShowSend==true){ 
          if(this.addressData.cityName == '成都'){
            sObj.shopingPoint = parseInt(sObj.shopingPoint*100);
            this.postAjax(this.sData.url.createOrder,sObj,(res)=>{
              if(res.status!==200){
                m$.template({
                  val:res.message,
                  time:1200
                })
              }else{
                //删除缓存时间
                m$.localStrages.remove('chooseTime');
                m$.localStrages.remove('value1');
                //0元支付
                if(Number(sObj.amountPaid)==0){
                  this.postAjax(this.sData.url.payWeixin,{ orderId : res.data,amount : 0},(res)=>{
                    if(res && res.message == 'OK' ){
                      m$.template({
                        val: '购买成功啦',
                        time: 1500
                      });
                      this.$router.replace('/orderList/-1');
                    }else {
                      m$.template({
                        val: '服务器开小差啦,请重试',
                        time: 1500
                      })
                    }
                  })
                }else{
                  this.$router.replace('/goPay/'+ res.data)
                  
                }
                
              }
            })
          }else{
            this.isChengduShow = true;
            m$.hiddenScroll(true);
          }
        }
        else {
          sObj.shopingPoint = parseInt(sObj.shopingPoint*100);
          this.postAjax(this.sData.url.createOrder,sObj,(res)=>{
            if(res.status!==200){
              m$.template({
                val:res.message,
                time:1200
              })
            }else{
              //删除缓存时间
              m$.localStrages.remove('chooseTime');
              m$.localStrages.remove('value1');
              //0元支付
              if(Number(sObj.amountPaid)==0){
                this.postAjax(this.sData.url.payWeixin,{ orderId : res.data,amount : 0},(res)=>{
                  if(res && res.message == 'OK' ){
                    m$.template({
                      val: '购买成功啦',
                      time: 1500
                    });
                    this.$router.replace('/orderList/-1');
                  }else {
                    m$.template({
                      val: '服务器开小差啦,请重试',
                      time: 1500
                    })
                  }
                })
              }else{
                console.log("跳转支付页面")
                this.$router.replace('/goPay/'+ res.data)
                
              }
            }
          })
        }
      },
      getAddr(oid){
        console.log('lalalllalalalalalalallalallalalallalallalallalalalalalalallalaallalalla');
        console.log(this.chooseTime)
        let ostatus=1;
        if(oid){
          ostatus='';
        }
        this.getAjax(this.sData.url.addressManage,
          {userId: this.sData.userId, isDefault:ostatus,receiveId:oid}, (res)=> {
            if(res&&res.data.length>0){

              this.isHasAddress=true;
              this.addressData=res.data[0]; 
              this.postData.provinceCode = this.addressData.provinceCode;
              this.postData.cityCode = this.addressData.cityCode;
              this.postData.districtCode = this.addressData.districtCode;
              this.postData.receiverAddress = this.addressData.provinceName+this.addressData.cityName+this.addressData.districtName+this.addressData.detailAddress;
              if(this.isShowSend == false){
                if(this.chooseTime.substr(6).length == 0){
                  this.postData.sendTime = this.chooseTime+":00";
                }else{
                  this.postData.sendTime = this.chooseTime.substr(6)+":00";
                }
              }
              this.getSendMethod();//获取快递方式
            }
            else {
              this.isHasAddress=false;
              this.addressData='';
            }
          })
      },
      getSendMethod () {//获取配送方式及运费
        let othis = this;
        let Ids = [];
        this.productMsg.map((item)=>{
          Ids.push(item.productId)
        })
        this.postData.productIds = Ids.join(',');
        //有地址信息是才发送运费请求
        if(this.postData.provinceCode){
          othis.postAjax(othis.sData.url.getMethod,othis.postData,(res)=>{
            if(res&&res.status==200){
              if(res.data.suppotType == 3){//圆通顺丰
                this.sendWay=res.data.expressShippings?res.data.expressShippings:[];
                if(this.sendWay.length>0){
                  let ways = this.sendWay.filter((item,idx)=>{
                    return item.shippingFreight
                  });
                  this.swObj=ways[0];
                }
                
                //this.swObj=this.sendWay[0];
                this.isGetEmsData=true;
              }else{
                this.swObj=res.data;
              }
              //积分可抵扣金额
              this.getPoint();
              console.log('200');
            }else{
              console.log('101');
              //this.isChengduShow=true;
              m$.template({
                val:res.message,
                time:1200
              })
            }
          })
        }
        
       
      },
      
      getPoint(){
        
        this.getAjax(this.sData.url.getShopingPoint,{userId:this.sData.userId},(res)=>{
          console.log('可用积分');
          console.log(this.allWillSend.amountPaid);
          console.log(Number(res.data/10000)==this.allWillSend.amountPaid);
          
          if((Number(res.data/100)>this.allWillSend.amountPaid)&&this.allWillSend.amountPaid!=0){
            this.myPoint = this.allWillSend.amountPaid*100;
          }else if(this.allWillSend.amountPaid==0&&this.allWillSend.shopingPoint != 0){
            this.myPoint = this.allWillSend.shopingPoint*100;
          }else{
            this.myPoint=res.data?res.data:0;
          }
          
        })
      },
      goSecletAddressFn(){
        this.$router.replace({name:'addressManage',params:{
          changeCheck:'true'
        }})
      },
      goSelectCouponFN(){
        if(this.couponText==true){
          var productIdArry=[];
          let prodId = m$.localStrages.get('orderItemBeans').map((item)=>{
            productIdArry.push(item.productId)
          })
          m$.localStrages.set('prodId',productIdArry)
          this.$router.replace({name:'coupon',params:{
            forPage:'true',id:'0',coupons:this.coupons
          }})
        }
        
      },
      // getCoupon(oid){
      //   this.getAjax(this.sData.url.couponId,
      //     {id:oid }, (res)=> {

      //       this.couponValue=res.data;
      //       this.accountMoney
      //     })
      // },
      getCoupon(){
        let oIds = [];
        let total = [];
        this.productMsg.map((item)=>{
          oIds.push(item.productId)
          total.push(item.price*item.number);
        })
        this.getCouponData.productIds = oIds.join(',');
        this.getCouponData.productTotalPrices = total.join(',');
        this.postAjax(this.sData.url.couponIds,
          this.getCouponData, (res)=> {
            if(res&&res.status==200){
              if(res.data.length>0){
                this.couponText = true;
                this.coupons = res.data;
              }else{
                this.couponText = false;
              }
            }
            
          })
      },
      upOperation(obool){
        this.openALert=false;
        if(obool==true){
          this.$router.replace({name:'productCar'})
        }
        else {

        }
      }


    },
    beforeRouteEnter(to,from,next){
      if(from.name!='addressManage'&&from.name!='coupon'&&from.path!='/'){
        //删除缓存时间
        m$.localStrages.remove(['chooseTime','value1']);
      }
      next();
    },
    created(){
      //回显时间段
      if(m$.localStrages.get('chooseTime')){
        this.chooseTime = m$.localStrages.get('chooseTime');
      }
      //设置默认日期 
      if(m$.localStrages.get('value1')){//如果是地址或者是优惠券跳转,回显时间
        console.log('回显时间')
        console.log(m$.localStrages.get('value1'));
        //if(m$.localStrages.get('value1').length>12){}
        //this.value1 = new Date(m$.localStrages.get('value1').replace(/\-/g,'/'))
        this.value1 = m$.localStrages.get('value1');
        console.log(this.value1);
      }else{ 
        if(new Date().getHours()>16){
          console.log('进这里来');
          var dd = new Date().getTime() + 86400000;
          dd = new Date(dd);
          var y = dd.getFullYear();
          var m = dd.getMonth()+1;
          var d = dd.getDate();
          this.value1 = y+"-"+m+"-"+d;
          console.log(this.value1);
        } else {
          this.value1 = new Date();
        }
      }
      //判断是不是今天(不是今天)
      console.log('判断是不是今天')
      console.log(typeof this.value1);
      console.log(this.value1);
      var JustNow;
      if(this.value1.length<12){
        console.log(new Date(this.value1.replace(/\-/g,'/')).getMonth());
        JustNow = new Date(this.value1.replace(/\-/g,'/'))
      }else{
        JustNow = new Date(this.value1);
      }
      
      if(JustNow.getFullYear()!=(new Date()).getFullYear()||JustNow.getMonth()!=(new Date()).getMonth()||JustNow.getDate()!=(new Date()).getDate()){
          console.log('初始不是今天')
          this.timeSlots = [];
          this.startHour = 12
          this.startMinute = "00"
          for(var i = 0;i< 20;i++){
              if (this.startMinute === "00"){
                  this.startMinute = "00"
                  this.endHour = this.startHour
                  this.endMinute = "30"
              } else {
                  this.startMinute = "30"
                  this.endHour = parseInt(this.startHour) + 1
                  this.endMinute = "00"
              }
              this.timeSlots.push(this.startHour + ":" + this.startMinute + "~" +this.endHour + ":" + this.endMinute)
              this.startHour = this.endHour
              this.startMinute = this.endMinute
          }
          this.timeSlots.push('22:00');
          console.log(m$.localStrages.get('chooseTime'));
          this.chooseTime = m$.localStrages.get('chooseTime')?m$.localStrages.get('chooseTime'):this.timeSlots[0];
          console.log(';QQQQQQQQQ');
          console.log(this.chooseTime);
      }else{
        console.log('初始是今天')
        this.timeSlot (true)
      }
      

      if(m$.localStrages.get('orderItemBeans').length>=1){
        let orderItemBeansArr=m$.localStrages.get('orderItemBeans');
        let isShowSend=true;
        var allNum=0;
        var allPrice=0;
        var proPrice = 0;
        var toolPrice =0;
        var finalPrice=0;
        console.log('shangpin');
        console.log(orderItemBeansArr);
        for(var i=0;i<orderItemBeansArr.length;i++){
          var sObj={
            thumbnail:orderItemBeansArr[i].img,
            name:orderItemBeansArr[i].name,
            sendType:'',
            intro:orderItemBeansArr[i].remark,
            quantity:orderItemBeansArr[i].number,
            price:orderItemBeansArr[i].price,
            proPrice:orderItemBeansArr[i].proPrice,
            toolPrice:orderItemBeansArr[i].toolPrice?orderItemBeansArr[i].toolPrice:0,
            productId :orderItemBeansArr[i].productId,
            cartId:orderItemBeansArr[i].id,
          };
          //所有商品总价
          finalPrice += sObj.price*sObj.quantity;
          this.allWillSend.orderItemBeans.push(sObj);
          allNum+=sObj.quantity;
          console.log('算价格啦');
          console.log(sObj.proPrice);
          allPrice += parseFloat(sObj.price);
          proPrice += parseFloat(sObj.proPrice);
          toolPrice += parseFloat(sObj.toolPrice);
          if(orderItemBeansArr[i].isCake =='1'){
            isShowSend=false;
          };
        }
        
        this.isShowSend=isShowSend;
        this.allWillSend.totalQuality=allNum;
        this.allWillSend.member=this.sData.userId;
        this.allWillSend.totalAmount=allPrice;
        this.allWillSend.proMoney=proPrice;
        this.allWillSend.toolPrice=toolPrice;
        this.allWillSend.finalPrice = finalPrice;
        //console.log(this.allWillSend.totalAmount);
      }
      else{

      }
      this.getAddr(this.addressId);
      //this.getCoupon(this.couponId);
      this.getCoupon();
      this.accountMoney();
      
      //设置优惠券抵扣价格
      if(this.$route.params.val){
        
        //商品价格
        var proRMB = Number(this.allWillSend.proMoney?this.allWillSend.proMoney:this.allWillSend.finalPrice);
        //加上配件之后的总价格
        var allProRMB = proRMB + Number(this.allWillSend.toolPrice?this.allWillSend.toolPrice:0);

        if(this.$route.params.val.priceExpression>allProRMB){//优惠券价格大于总价格

          this.couponValue = Number(allProRMB);//只优惠总价格(不含运费)
        }else{
          this.couponValue = Number(this.$route.params.val.priceExpression); 
        }
        
      }else{
        this.couponValue = 0;
      }
      
    },
    props:["sData"],
    beforeDestroy (){
      m$.dom('html')[0].style.overflow = 'auto';
      m$.localStrages.remove('coupon');
    },
    watch:{
      'isCanUsePoint':function (val) {
        console.log('积分抵扣query')
        console.log(val);
        if(val.length>=1){
          this.allWillSend.shopingPoint=val[0]/100;

        }
        else {
          this.allWillSend.shopingPoint=0;
        }
        this.accountMoney();
      },
      'swObj':function (val) {
        console.log('运费')
        console.log(this.swObj)
        this.allWillSend.freight = 0;
        if(val.dayPrice){
          if(this.allWillSend.proMoney||this.allWillSend.proMoney==0){
            if(val.dayPrice<=this.allWillSend.proMoney+this.allWillSend.toolPrice){
              this.allWillSend.freight=0;
            }else{
              this.allWillSend.freight=val.shippingFreight;
            }
          }
          else if(val.dayPrice<=this.allWillSend.finalPrice+this.allWillSend.toolPrice){
            this.allWillSend.freight=0;
          }
          else {
            this.allWillSend.freight=val.shippingFreight;
          }
        }else{
          this.allWillSend.freight=val.shippingPrice;
        }
        
        this.accountMoney();
      },
      'value1':function(val){
        console.log('在这里吗?&&&&&&&&&&&')
        console.log(val);
        console.log(typeof val);
        var dd = new Date();
        var y = dd.getFullYear();
        var m = dd.getMonth()+1;
        var d = dd.getDate();
        var nowDay = y+"-"+m+"-"+d;
       
        if(typeof val == 'number'){
          val = new Date(val)
        }else if(typeof val == 'string'){
          val = val.substring(0,10);
        }
        if(typeof this.value1 == 'number'){
          this.value1 = new Date(this.value1)
        }else if(typeof this.value1 == 'string'){
          this.value1 = this.value1.substring(0,10);
        }

        if(JSON.stringify(this.value1).length>12){
          m$.localStrages.set('value1',this.value1.getTime());
        }
        
        var val1;
        if(JSON.stringify(val).length>12){
          var y1 = val.getFullYear();
          var m1 = val.getMonth()+1;
          var d1 = val.getDate();
          val1 = y1+"-"+m1+"-"+d1;
          
        }else{
          
          val1 = val;
          console.log('在这里吗?')
          console.log(val1);
           console.log(nowDay);
        }
        
        if(val1 != nowDay){
          
          console.log(val1);
          console.log(nowDay);
          console.log('不是今天')
          if(typeof val == 'object'){
            m$.localStrages.set('value1',val.getTime());
          }else{
            m$.localStrages.set('value1',val);
          }
          
          console.log(typeof val)
          console.log(val)
          console.log(typeof m$.localStrages.get('value1'))

          console.log(m$.localStrages.get('value1'))
          this.timeSlots = [];
          this.startHour = "12";
          this.startMinute = "00";
          for(var i = 0;i<20;i++){
            if (this.startMinute+30>59){
                this.endHour = parseInt(this.startHour) + 1
                this.endMinute = "00"
            } else {
                this.endHour = this.startHour
                this.endMinute = "30"
            }
            this.timeSlots.push(this.startHour + ":" + this.startMinute + "~" +this.endHour + ":" + this.endMinute)   
            this.startHour = this.endHour
            this.startMinute = this.endMinute
          }
          this.timeSlots.push('22:00');
          console.log('nononono')
          // //重置配送时段
          // this.chooseTime = this.timeSlots[0];
          // m$.localStrages.set('chooseTime',this.chooseTime);
          //上传后台,获取运费
          if(this.chooseTime.substr(6).length == 0){
            this.postData.sendTime = this.chooseTime+":00";
          }else{
            this.postData.sendTime = this.chooseTime.substr(6)+":00";
          }
          //判断是否还用之前选的时段(如果有则不变)
          if(m$.localStrages.get('chooseTime')){
            console.log('判断是否还用之前选的时段(如果有则不变)')
            console.log(m$.localStrages.get('chooseTime'))
            if(
              this.timeSlots.filter((item)=>{
                if(item==m$.localStrages.get('chooseTime')){return item;}
              })
            ){
              this.chooseTime = m$.localStrages.get('chooseTime');
            console.log(this.chooseTime)
              //上传后台,获取运费
              if(this.chooseTime.substr(6).length == 0){
                this.postData.sendTime = this.chooseTime+":00";
              }else{
                this.postData.sendTime = this.chooseTime.substr(6)+":00";
              }
            }else{
              this.chooseTime = this.timeSlots[0];
              m$.localStrages.set('chooseTime',this.chooseTime);
              //上传后台,获取运费
              if(this.chooseTime.substr(6).length == 0){
                this.postData.sendTime = this.chooseTime+":00";
              }else{
                this.postData.sendTime = this.chooseTime.substr(6)+":00";
              }
              
            }
          }
          else{
            this.chooseTime = this.timeSlots[0];
            m$.localStrages.set('chooseTime',this.chooseTime);
            //上传后台,获取运费
            if(this.chooseTime.substr(6).length == 0){
              this.postData.sendTime = this.chooseTime+":00";
            }else{
              this.postData.sendTime = this.chooseTime.substr(6)+":00";
            }
          }
      
          
        } else if(val.getFullYear()!=(new Date()).getFullYear()||val.getMonth()!=(new Date()).getMonth()||val.getDate()!=(new Date()).getDate()){
          this.timeSlots = [];
          this.startHour = "12";
          this.startMinute = "00";
          for(var i = 0;i<20;i++){
            if (this.startMinute+30>59){
                this.endHour = parseInt(this.startHour) + 1
                this.endMinute = "00"
            } else {
                this.endHour = this.startHour
                this.endMinute = "30"
            }
            this.timeSlots.push(this.startHour + ":" + this.startMinute + "~" +this.endHour + ":" + this.endMinute)   
            this.startHour = this.endHour
            this.startMinute = this.endMinute
          }
          this.timeSlots.push('22:00');
          //判断是否还用之前选的时段
          if(this.timeSlots.filter((item)=>{
            if(item==m$.localStrages.get('chooseTime')){return item;}
          })){
            console.log('时间段选择')
            this.chooseTime = m$.localStrages.get('chooseTime');
            //上传后台,获取运费
            if(this.chooseTime.substr(6).length == 0){
              this.postData.sendTime = this.chooseTime+":00";
            }else{
              this.postData.sendTime = this.chooseTime.substr(6)+":00";
            }
          }else{
            
            this.chooseTime = this.timeSlots[0];
            m$.localStrages.set('chooseTime',this.chooseTime);
            //上传后台,获取运费
            if(this.chooseTime.substr(6).length == 0){
              this.postData.sendTime = this.chooseTime+":00";
            }else{
              this.postData.sendTime = this.chooseTime.substr(6)+":00";
            }
          }
        } else {
          console.log('今天');
          this.timeSlot(false);
        }

        //改变日期时 发请求获取新的运费
        console.log('发送后台的发货时间')
        console.log(m$.localStrages.get('chooseTime'));
        console.log(this.postData.sendTime);
        this.getSendMethod();
      }
    }
  }
</script>
<style scoped lang="less">
    @import "sureOrder";
    @import "../cs/cs.less";
</style>
